package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 执行DDL语句(删除db2里面的student)
 */
public class Demo05 {
    public static void main(String[] args) {
        Connection con = null;
        Statement sta = null;
        try {
            //注册驱动
            Class.forName("com.mysql.jdbc.Driver");
            //获取连接对象
            con = DriverManager.getConnection("jdbc:mysql:///db2", "root", "myroot");
            //定义SQL语句
            String sqL = "drop table student";
            //获取执行sql对象
            sta = con.createStatement();
            int i = sta.executeUpdate(sqL);
            System.out.println(i);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                sta.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}
